﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Office365.SharePointOnline.Cmdlets
{
    public class AuthenticationServiceLocator : IServiceLocator
    {
        private IDictionary<object, object> services;

        public AuthenticationServiceLocator()
        {
            services = new Dictionary<object, object>();
 
            // fill the map
            this.services.Add(typeof(SharePointOnlineService), new SharePointOnlineService());
            this.services.Add(typeof(OnPremiseService), new OnPremiseService());
        }
 
        public T GetService<T>()
        {
            try
            {
                return (T)services[typeof(T)];
            }
            catch (KeyNotFoundException)
            {
                throw new ApplicationException("The requested service is not registered");
            }
        }
    }
}
